﻿using System.Globalization;
using System.Web.Mvc;
using Matrix.MaKaYunShang.BLL;
using Matrix.MaKaYunShang.Model;
using Matrix.MaKaYunShang.Model.Enum;

namespace Matrix.MaKaYunShang.McMagWeb.Controllers
{
    [Authorization]
    public class PhysicalController : BaseController
    {
        [PermissionFilter]
        public ActionResult List()
        {
            return View();
        }


        [HttpPost]
        public JsonResult Listing(int draw, int start, int length)
        {
            int order;
            int.TryParse(Request["order[0][column]"], out order);
            var direction = Request["order[0][dir]"];
            var orderByColumns = new[] { "CloudCardId", "CardCode", "LogisticsNum", "LogisticsCompany", "('姓名:'+ca.LinkMan+'  电话:'+ca.LinkMobile+LinkMobile+'  地址:'+AddressDetail)", "VerifyTime" };
            var search = Request["search[value]"];
            var pageIndex = (start / length) + 1;
            var theList = UserCardBLL.Instance.GetPagingList(draw, pageIndex, length, SqlSafe(search), orderByColumns[order] + " " + direction, ((int)CloudCardEnum.CategoryCode.现场实物劵).ToString(CultureInfo.InvariantCulture) + "," + ((int)CloudCardEnum.CategoryCode.实物劵).ToString(CultureInfo.InvariantCulture), CurrentUser.ShopId.ToString(), (int)CloudCardEnum.UserCardStatus.已核销);
            return Json(theList);
        }
      
        [HttpPost]
        public ActionResult SavePostRecord(UserCard model)
        {
            var result = new Result() { Status = false, Message = "添加失败" };
            var userCard = UserCardBLL.Instance.GetModel(model.Id);
            if (userCard != null)
            {
                userCard.LogisticsCompany = model.LogisticsCompany;
                userCard.LogisticsNum = model.LogisticsNum;
                result.Status = UserCardBLL.Instance.Update(userCard);

            }

            return Json(result);
        }
    }
}